/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/05/20
* File: SceneGraph.cpp
* Blog: http://www.cnblogs.com/zengqh/
**/

#include "enn_scene_graph.h"

namespace enn
{
SceneGraph::SceneGraph()
{

}

SceneGraph::~SceneGraph()
{

}

SceneNode* SceneGraph::createSceneNode(ClassType type, const std::string& name)
{
	CreatorType fn = findCreator( type );
	if ( fn )
	{
		return fn();
	}

	return 0;
}

SceneGraph::CreatorType SceneGraph::findCreator( ClassType type ) const
{
	CreatorMap::const_iterator it = creator_map_.find(type);
	if ( it != creator_map_.end() )
	{
		return it->second;
	}

	return 0;
}

template<class T>
void SceneGraph::registerCreator()
{
	if ( findCreator(ENN_CLASS_TYPE(T)) )
	{
		ENN_ASSERT(0);
		return;
	}

	creator_map_.insert(ENN_CLASS_TYPE(T), _createSceneNode<T>);
}

void SceneGraph::init()
{

}

template<class T>
static SceneNode* _createSceneNode()
{
	return new T();
}
}
